local wezterm = require("wezterm")
local act = wezterm.action
local module = {}

function module.apply(config)
  -- Disable default key bindings
  config.disable_default_key_bindings = true
  -- Leader
  config.leader = {
    key = "s",
    mods = "CTRL"
  }
  -- key bindings
  config.keys = {
    -- split pane vertically or horizontally
    {
      key = "-",
      mods = "LEADER",
      action = act.SplitVertical {
        domain = "CurrentPaneDomain"
      }
    },
    {
      key = "=",
      mods = "LEADER",
      action = act.SplitHorizontal {
        domain = "CurrentPaneDomain"
      }
    },
    -- pane navigation
    {
      key = "h",
      mods = "LEADER",
      action = act {
        ActivatePaneDirection = "Left"
      }
    },
    {
      key = "j",
      mods = "LEADER",
      action = act {
        ActivatePaneDirection = "Down"
      }
    },
    {
      key = "k",
      mods = "LEADER",
      action = act {
        ActivatePaneDirection = "Up"
      }
    },
    {
      key = "l",
      mods = "LEADER",
      action = act {
        ActivatePaneDirection = "Right"
      }
    },
    -- Toggles the zoom state of the current pane.
    {
      key = "z",
      mods = "LEADER",
      action = act.TogglePaneZoomState
    },
    -- paste from the clipboard
    {
      key = "V",
      mods = "CTRL",
      action = act.PasteFrom 'Clipboard'
    },
    -- Activate the Launcher Menu in the current tab
    {
      key = "L",
      mods = "CTRL",
      action = act.ShowLauncher
    },

    -- ActivateTabRelativeNoWrap
    {
      key = "p",
      mods = "LEADER",
      action = act.ActivateTabRelativeNoWrap(-1),
    },
    {
      key = "n",
      mods = "LEADER",
      action = act.ActivateTabRelativeNoWrap(1),
    },

    -- Close the current tab, terminating all contained panes.
    {
      key = "w",
      mods = "CTRL",
      action = act.CloseCurrentTab { confirm = true },
    },

    {
      key = "Enter",
      mods = "SHIFT",
      action = act.SendString '\x1b[13;2u'
    },

  }

  -- Activate Tab
  for i = 1, 4 do
    table.insert(config.keys, {
      key = tostring(i),
      mods = "ALT",
      action = act.ActivateTab(i - 1),
    })
  end

end

return module

